package interceptor;

/**
 * 登陆拦截类
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("user_token");
        log.info("获取token:{}",token);
        String url=request.getRequestURI();
        log.info("获取路径:{}",url);
        //解析令牌
        Claims claims= JWTUtil.parseJWT(token);
        if(claims==null){
            log.error("解析JWT令牌失败!");
            response.setStatus(401);
            return false;
        }
        log.info("解析令牌成功,放行");
        return true;
    }
}
